<!-- 服务商确认代办入口主页面 -->
<template>
  <div>
    <el-header v-if="this.paramsObj.workItemId" height="36px">
      <header-title :title="headerTitle" />
    </el-header>
    <!-- 项目基础信息 -->
    <ProjectBasicInfo :prj-id="paramsObj.prjId" :prj-type="'A'" />
    <!-- 站址信息 -->
    <ProjectSiteInfo v-if="isShowAttachMent" :prj-id="paramsObj.prjId" />
    <!-- 项目专属信息 -->
    <ProjectExclusiveinfo :prj-id="paramsObj.prjId" :prj-type="'A'" />
    <!-- 商合采购订单-->
    <SuppierConfirm v-if="isTag" :params-obj="paramsObj" :prjDetails="prjDetails"/>
    <!-- 附件  -->
    <ProjectAttachmentInfo v-if="isShowAttachMent" :params-obj="attachmentInfo" />
  </div>
</template>

<script>
import HeaderTitle from '@/components/basic/HeaderTitle'
import ProjectBasicInfo from '@/components/jn/JnPrjDetail'
import ProjectSiteInfo from '@/components/jn/JnSiteDetail'
import ProjectExclusiveinfo from '@/components/jn/JnProprietaryDetail'
import ProjectAttachmentInfo from '../projectInfo/projectAttachmentInfo.vue'
import SuppierConfirm from './suppierConfirm.vue'
import { getWFWorkItem } from '@/api/actualBudget/index'
import {getPrjDetail} from '@/api/actualBudget'
import { getQueryObject } from '@/utils'
import {
    getOnlyId
} from '@/api/settlement/balanceSettlement.js'
export default {
    name: 'Balance',
    components: {
        ProjectBasicInfo,
        ProjectSiteInfo,
        ProjectExclusiveinfo,
        SuppierConfirm,
        ProjectAttachmentInfo,
        HeaderTitle
    },
    data() {
        return {
            headerTitle: '',
            isTag: false, // 由于异步组件通信所以需要判断是否有值
            // 浏览器解析出来需要的字段
            paramsObj: {
                prjId: '',
                adjustId: '',
                workItemId: '',
                processInstId: '',
                titles: '',
                type: ''
            },
            // 给附件传递的浏览器参数
            attachmentInfo: {
                prjId: '',
                nodeId: '',
                prjStage: 'Q1',
                btnConfig: 'A', // 默认传A .综合查询传B// btnConfig:  A:默认，B：下载附件  C：默认+全览  D:下载附件+全览  E：默认+全览+数字图纸   F：补传
                isChange: '0', // 默认传0
                prjType: '',
                buildModes: '',
                towerType: '0',
                roomType: '0',
                pageSite: '',
                orgId:'',
                projectId:''
            },
            prjDetails:{},
            isShowAttachMent: false
        }
    },
    created() {
        this.getBalanceInfo()
    },
    methods: {
        // 获取从综合查询进来的adjustid
        async getInitOnlyId() {
            const { code, data } = await getOnlyId(this.paramsObj.prjId)
            if (+code === 200) {
                this.isTag = true
                this.paramsObj.adjustId = data?.adjId
                this.getAttachmentInfo()
            }
        },
        // 给附件传递的信息
        async getAttachmentInfo() {
            if (!this.paramsObj.prjId) {
                return
            }
            const { code, data } = await getPrjDetail({ prjId: this.paramsObj.prjId })
            if (+code === 200) {
                this.prjDetails =data
                this.headerTitle = data?.prjName
                this.paramsObj.titles = data?.prjName
                this.attachmentInfo.prjId = this.paramsObj.prjId
                this.attachmentInfo.prjType = data.prjType
                this.attachmentInfo.buildModes = data.buildModes
                this.attachmentInfo.orgId = data?.orgId
                this.attachmentInfo.projectId = this.paramsObj.prjId
                this.isShowAttachMent = true
                if (this.paramsObj.workItemId) {
                    this.attachmentInfo.btnConfig = this.paramsObj.type === 'done' ? 'B' : 'A'
                } else {
                    this.attachmentInfo.btnConfig = 'B'
                    // 综合查询旧页面
                    this.attachmentInfo.pageSite = 'attachmentInfo'
                }
            }
        },
        // 页面初始化获取processInid 流程节点 以及浏览器地址数据
        async getBalanceInfo() {
            // 浏览器地址 获取参数
            const obj = getQueryObject()
            this.paramsObj.prjId = obj?.prjId
            this.paramsObj.adjustId = obj?.adjustId
            this.paramsObj.workItemId = obj?.workItemId
            this.paramsObj.processInstId = obj?.processInstId
            this.paramsObj.type = obj?.type
            // 综合查询进来的
            if (!this.paramsObj.workItemId) {
                this.getInitOnlyId()
            } else {
                const { workItemId } = this.paramsObj
                const { code, data } = await getWFWorkItem({ workItemId: workItemId })
                if (+code === 200) {
                    this.isTag = true
                    this.paramsObj.processInstId = data.processInstID.toString()
                    this.attachmentInfo.nodeId = data.activityDefID
                    this.paramsObj.prjId = data.bizObject.prjId
                    this.paramsObj.adjustId = data.bizObject?.bizSeq
                    this.getAttachmentInfo()
                } else {
                    throw new Error('获取流程信息失败')
                }
            }
        }
    }
}
</script>
<style lang="scss" scoped></style>
